/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.hpvas.gui.internalframe;

import edu.hpvas.control.AppointmentController;
import edu.hpvas.control.Login;
import edu.hpvas.control.OwnerController;
import edu.hpvas.control.PetController;
import edu.hpvas.control.Restrictions;
import edu.hpvas.control.VeterinarianController;
import edu.hpvas.persistence.entity.Appointment;
import edu.hpvas.persistence.entity.Owner;
import edu.hpvas.persistence.entity.Person;
import edu.hpvas.persistence.entity.Pet;
import edu.hpvas.persistence.entity.Veterinarian;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JOptionPane;
import sun.security.krb5.internal.APOptions;

/**
 *
 * @author sony
 */
public class AppointmentFrame extends javax.swing.JInternalFrame {

    OwnerController ownerC= new OwnerController();
    Restrictions restric = new Restrictions();
    ArrayList<Owner> owners = new ArrayList<>();
    ArrayList<Pet> pets = new ArrayList<>();
    Pet pet = new Pet();
    Owner owner = new Owner();
    /**
     * Creates new form AppointmentFrame
     */
    public AppointmentFrame() {
        initComponents();
        int ancho=800;
         int alto=500;
         setSize(ancho, alto);
         errorJL.setVisible(false);
         petPanelJP.setVisible(false);
         appointInfoJP.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        ownerPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        nameJTF = new javax.swing.JTextField();
        nameJCB = new javax.swing.JComboBox();
        selectJB = new javax.swing.JButton();
        errorJL = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        petPanelJP = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        petsJC = new javax.swing.JComboBox();
        selectJB1 = new javax.swing.JButton();
        backJB = new javax.swing.JButton();
        appointInfoJP = new javax.swing.JPanel();
        chargeJL = new javax.swing.JLabel();
        chargejT = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        monthJCB = new javax.swing.JComboBox();
        dayJL = new javax.swing.JLabel();
        dayJCB = new javax.swing.JComboBox();
        yearJCB = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        errorMJL = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Set Appointment", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.red));

        ownerPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Owner Information\n", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 153)));

        jLabel1.setText("Search by name & Last Name");

        nameJTF.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                nameJTFMouseClicked(evt);
            }
        });

        selectJB.setText("Select");
        selectJB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectJBActionPerformed(evt);
            }
        });

        errorJL.setForeground(new java.awt.Color(204, 0, 0));
        errorJL.setText("The special caracters are not allowed... try again");

        jButton1.setText("Enter");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ownerPanelLayout = new javax.swing.GroupLayout(ownerPanel);
        ownerPanel.setLayout(ownerPanelLayout);
        ownerPanelLayout.setHorizontalGroup(
            ownerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ownerPanelLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(ownerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ownerPanelLayout.createSequentialGroup()
                        .addGap(152, 152, 152)
                        .addComponent(errorJL, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(ownerPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(ownerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(ownerPanelLayout.createSequentialGroup()
                                .addComponent(nameJTF, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton1))
                            .addGroup(ownerPanelLayout.createSequentialGroup()
                                .addComponent(nameJCB, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(selectJB, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(81, Short.MAX_VALUE))
        );
        ownerPanelLayout.setVerticalGroup(
            ownerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ownerPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(ownerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nameJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(8, 8, 8)
                .addComponent(errorJL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ownerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameJCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(selectJB)))
        );

        petPanelJP.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Selection Pet", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black));

        jLabel2.setText("Pets Of This Owner");

        selectJB1.setText("Select");
        selectJB1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectJB1ActionPerformed(evt);
            }
        });

        backJB.setText("Back");
        backJB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backJBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout petPanelJPLayout = new javax.swing.GroupLayout(petPanelJP);
        petPanelJP.setLayout(petPanelJPLayout);
        petPanelJPLayout.setHorizontalGroup(
            petPanelJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(petPanelJPLayout.createSequentialGroup()
                .addGap(62, 62, 62)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(petsJC, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(petPanelJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(backJB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(selectJB1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        petPanelJPLayout.setVerticalGroup(
            petPanelJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(petPanelJPLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(petPanelJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(petsJC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(selectJB1))
                .addGap(18, 18, 18)
                .addComponent(backJB)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        appointInfoJP.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Appoint Information", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        chargeJL.setText("Charge");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel7.setText("Month");

        monthJCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-------", "January", "Febrary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", " " }));
        monthJCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monthJCBActionPerformed(evt);
            }
        });

        dayJL.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        dayJL.setText("Day");

        dayJCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dayJCBActionPerformed(evt);
            }
        });

        yearJCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "----", "2012", "2011", "2010", "2009", "2008", "2007", "2006", "2005", "2004", "2003", "2002", "2001", "2000", "1999", "1998", "1997", "1996", "1995", "1994", "1993", "1992", "1991", "1990", "1989", "1988", "1987", "1986", "1985", "1984", "1983", "1982", "1981", "1980", "1979", "1978", "1977", "1976", "1975", "1974", "1973", "1972", "1971", "1970", "1969", "1968", "1967", "1966", "1965", "1964", "1963", "1962", "1961", "1960", "1959", "1958", "1957", "1956", "1955", "1954", "1953", "1952", "1951", "1950", "1949", "1948", "1947", "1946", "1945", "1944", "1943", "1942", "1941", "1940", "1939", "1938", "1937", "1936", "1935", "1934", "1933", "1932", "1931", "1930", "1929", "1928", "1927", "1926", "1925", "1924", "1923", "1922", "1921", "1920" }));
        yearJCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yearJCBActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel8.setText("Year");

        errorMJL.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        errorMJL.setForeground(new java.awt.Color(204, 0, 0));
        errorMJL.setText("The date is Uncompleted");

        jLabel4.setText("Date");

        jButton2.setText("Set Appointment");
        jButton2.setToolTipText("");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout appointInfoJPLayout = new javax.swing.GroupLayout(appointInfoJP);
        appointInfoJP.setLayout(appointInfoJPLayout);
        appointInfoJPLayout.setHorizontalGroup(
            appointInfoJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(appointInfoJPLayout.createSequentialGroup()
                .addGap(69, 69, 69)
                .addGroup(appointInfoJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(appointInfoJPLayout.createSequentialGroup()
                        .addGroup(appointInfoJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(appointInfoJPLayout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(yearJCB, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(appointInfoJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(appointInfoJPLayout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(monthJCB, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(dayJL)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(dayJCB, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(errorMJL, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addGap(52, 52, 52))
                    .addGroup(appointInfoJPLayout.createSequentialGroup()
                        .addComponent(chargeJL)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chargejT, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        appointInfoJPLayout.setVerticalGroup(
            appointInfoJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(appointInfoJPLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(appointInfoJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chargeJL)
                    .addComponent(chargejT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(appointInfoJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(errorMJL)
                    .addComponent(jLabel4)
                    .addComponent(jButton2))
                .addGap(10, 10, 10)
                .addGroup(appointInfoJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(monthJCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(yearJCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dayJL)
                    .addComponent(dayJCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(appointInfoJP, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ownerPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(petPanelJP, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(ownerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(petPanelJP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(appointInfoJP, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void nameJTFMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nameJTFMouseClicked

        if(nameJTF.getText().equals("The field Cannot be Blank")){
            nameJTF.setText("");
            nameJTF.setForeground(Color.black);
        }
    }//GEN-LAST:event_nameJTFMouseClicked

    private void selectJBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectJBActionPerformed
        if(nameJCB.getSelectedIndex()!=0){
            PetController petController = new PetController();
            owner= owners.get(nameJCB.getSelectedIndex()-1);
            nameJTF.setText("");
            nameJCB.removeAll();
            nameJCB.setVisible(false);
            selectJB.setVisible(false);
            pets= petController.petByOwner(owner.getId());
            if(!pets.isEmpty()){
                petsJC.addItem("-----------");
                petPanelJP.setVisible(true);
                for(Pet p:pets){
                    petsJC.addItem(p.getName() + " - "  + p.getSpecies());
                }

            }
            nameJCB.setVisible(false);
            selectJB.setVisible(false);
        }
    }//GEN-LAST:event_selectJBActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        errorJL.setVisible(false);
        nameJCB.removeAllItems();
        if(nameJTF.getText().equals("") || nameJTF.getText().equals("The field Cannot be Blank")){
            nameJTF.setText("The field Cannot be Blank");
            nameJTF.setForeground(Color.red);
        }
        else if(!restric.validateSpecialC(nameJTF.getText())){
            errorJL.setVisible(true);
        }
        else{
            owners = ownerC.searchOwners(nameJTF.getText());
            if(!owners.isEmpty()){
                nameJCB.addItem("-----------");
                nameJCB.setVisible(true);
                selectJB.setVisible(true);
                for(Owner o:owners){
                    nameJCB.addItem(o.getIdPerson().getName() + " " + o.getIdPerson().getLastName());
                }

            }
            else{
                nameJCB.setVisible(false);
                selectJB.setVisible(false);
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void selectJB1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectJB1ActionPerformed
        if(petsJC.getSelectedIndex()!=0){
            pet= pets.get(petsJC.getSelectedIndex()-1);
            appointInfoJP.setVisible(true);
            
        }
        else{
            JOptionPane.showMessageDialog(this, "invalid Option");
        }
    }//GEN-LAST:event_selectJB1ActionPerformed

    private void backJBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backJBActionPerformed
        petPanelJP.setVisible(false);
    }//GEN-LAST:event_backJBActionPerformed

    private void monthJCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monthJCBActionPerformed
        errorMJL.setVisible(false);
        dayJCB.setVisible(false);
        dayJL.setVisible(false);
        monthSelected();
        if(monthJCB.getSelectedIndex()!=0){
            if(yearJCB.getSelectedIndex()!=0){
                dayJCB.setVisible(true);
                dayJL.setVisible(true);
            }
        }
    }//GEN-LAST:event_monthJCBActionPerformed

    private void dayJCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dayJCBActionPerformed
        errorMJL.setVisible(false);
    }//GEN-LAST:event_dayJCBActionPerformed

    private void yearJCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearJCBActionPerformed
        errorMJL.setVisible(false);
        dayJCB.setVisible(false);
        dayJL.setVisible(false);
        if(yearJCB.getSelectedIndex()!=0){
            if(monthJCB.getSelectedIndex()!=0){
                dayJCB.setVisible(true);
                dayJL.setVisible(true);
            }
        }
        monthSelected();
    }//GEN-LAST:event_yearJCBActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        if(!chargejT.getText().isEmpty() && dayJCB.getSelectedIndex()>0 && 
                monthJCB.getSelectedIndex()>0 && dayJCB.getSelectedIndex()>0){
            Appointment appoint = new Appointment();
            appoint.setCharge(new Integer(chargejT.getText()));
            appoint.setDate(new Date(113-yearJCB.getSelectedIndex(), monthJCB.getSelectedIndex()+1, dayJCB.getSelectedIndex()));
            AppointmentController appointC= new AppointmentController();
            VeterinarianController vetContr = new VeterinarianController();
            Person p = Login.currentPerson;
            Veterinarian currentVeterinarian = vetContr.getVeterinarian(p);
            
            if(appointC.setAppointment(appoint,currentVeterinarian, pet)){
                JOptionPane.showMessageDialog(this, "The Appointment was setted successfully");
            }
            else{
                JOptionPane.showMessageDialog(this, "Error, try Again");
            }
            
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void monthSelected(){
        int mes = monthJCB.getSelectedIndex();
        dayJCB.removeAllItems();
        dayJCB.addItem("--");
        if(mes ==1 || mes == 3 || mes == 5 || mes == 7 || mes ==8 || mes ==10 || mes == 12)
        {   
            for(int i=1; i<=31;i++)
            {
                dayJCB.addItem(i);
            }
        }
        else if(mes ==4 || mes ==6 || mes ==9 || mes ==11)
        {
            for(int i=1;i<=30;i++)
            {
                dayJCB.addItem(i);
            }
        }
        else if(mes ==2)
        {
            for(int i=1;i<=28;i++)
            {
                dayJCB.addItem(i);
            }
            if((2013-yearJCB.getSelectedIndex())%4 ==0)
            {
                dayJCB.addItem(29);
            }

        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel appointInfoJP;
    private javax.swing.JButton backJB;
    private javax.swing.JLabel chargeJL;
    private javax.swing.JTextField chargejT;
    private javax.swing.JComboBox dayJCB;
    private javax.swing.JLabel dayJL;
    private javax.swing.JLabel errorJL;
    private javax.swing.JLabel errorMJL;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox monthJCB;
    private javax.swing.JComboBox nameJCB;
    private javax.swing.JTextField nameJTF;
    private javax.swing.JPanel ownerPanel;
    private javax.swing.JPanel petPanelJP;
    private javax.swing.JComboBox petsJC;
    private javax.swing.JButton selectJB;
    private javax.swing.JButton selectJB1;
    private javax.swing.JComboBox yearJCB;
    // End of variables declaration//GEN-END:variables
}
